package com.hb.game.pk.adpter;

import android.app.Activity;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hb.game.pk.R;
import com.hb.game.pk.beans.ErBaXiaZhuInfo;
import com.hb.game.pk.beans.IndexGame;
import com.hb.game.pk.utils.LogUtils;
import com.hb.game.pk.utils.SpannableStringUtils;
import com.hb.game.pk.utils.StringUtils;

public class ErBaRecordListAdapter extends BaseQuickAdapter<ErBaXiaZhuInfo.DataBean, BaseViewHolder> {
    private Activity act;

    public ErBaRecordListAdapter(int layoutResId, Activity act) {
        super(layoutResId);
        this.act = act;
    }

    @Override
    protected void convert(BaseViewHolder helper, ErBaXiaZhuInfo.DataBean item) {
        helper.setText(R.id.tv_xz_title, "下注详情");
        helper.setText(R.id.tv_zj_title, "中奖结果");
        String hb_money = "0";
        if (!StringUtils.isEmpty(item.getHb_money()))
            hb_money = Float.parseFloat(item.getHb_money()) / 100 + "";
        int t_num = item.getNum();
        String num = "";
        if (t_num < 10) {
            num = t_num + "点";
        } else if (t_num >= 10 && t_num < 100) {
            num = "对子";
        } else if (t_num == 100) {
            num = "28杠";
        }
        int tz_num = item.getZhuang_num();
        String z_num = "";
        if (tz_num < 10) {
            z_num = tz_num + "点";
        } else if (tz_num >= 10 && tz_num < 100) {
            z_num = "对子";
        } else if (tz_num == 100) {
            z_num = "28杠";
        }
        String z_money = "0";
        SpannableStringBuilder spannableStringBuilder = null;
        if (!StringUtils.isEmpty(item.getZhuang_money())) {
            z_money = String.format("%.2f", Float.parseFloat(item.getZhuang_money()) / 100f);
            String[] split = z_money.split("\\.");
            spannableStringBuilder = SpannableStringUtils.getBuilder(split[0])
                    .setForegroundColor(act.getResources().getColor(R.color.c_ffffff))
                    .append("." + split[1])
                    .setForegroundColor(act.getResources().getColor(R.color.c_fd453b))
                    .append("/" + z_num)
                    .setForegroundColor(act.getResources().getColor(R.color.c_ffffff))
                    .create();
        } else {
            spannableStringBuilder = SpannableStringUtils.getBuilder("0/" + z_num + "点")
                    .setForegroundColor(act.getResources().getColor(R.color.c_ffffff))
                    .create();
        }
        helper.setText(R.id.tv_kj_num, String.format(act.getResources().getString(R.string.item_erba_qihao), item.getChang_id()));
        TextView view = (TextView) helper.getView(R.id.tv_lingbao);
        view.setText(spannableStringBuilder);
        helper.setText(R.id.tv_xz_val, (Float.parseFloat(item.getMoney()) / 100f) + "");
        helper.setText(R.id.tv_zj_val, hb_money + "/" + num + "/" + item.getRemark() + "(" + String.format("%.2f", Float.parseFloat(item.getPeifu()) / 100f) + ")");
    }

}
